package com.ftg.learn.bus.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.learn.bus.entity.Director;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 负责人表 Mapper 接口
 * </p>
 *
 * @author lalala
 * @since 2022-03-07
 */
public interface DirectorMapper extends BaseMapper<Director> {



    /**
     * 查询车的信息和负责人的信息
     * @return data
     */
    @Select("select bus_name, bus_no, engine_no, frame_no, ins_equ_no, receiver, unit, manufacturer, park, displacement, category, purpose, bus_photos, remarks ,dname ,dphone from sys_director as a left join sys_bus_info as b on a.did = b.did")
    List<Map<String,Object>> showDirectorBusInfo();


    /**
     * 根据负责人查询其负责的车的信息
     * @param did 负责人id
     * @return data
     */
    @Select("select bus_name, bus_no, engine_no, frame_no, ins_equ_no, receiver, unit, manufacturer, park, displacement,category, purpose, bus_photos, remarks ,dname ,dphone from sys_director as a left join sys_bus_info as b on a.did = b.did where b.did = #{did}")
    List<Map<String,Object>> showDirectorBusInfoByDid(@Param("did") Long did);


    /**
     * 修改公车信息的负责人
     * @param did id
     * @param bid id
     * @return true
     */
    @Update("update sys_bus_info set did  = #{did} where bid = #{bid}")
    boolean updateBusInfoByBid(@Param("did") Long did,@Param("bid") Long bid);

    /**
     * 获取公车表did
     * @param bid id
     * @return long
     */
    @Select("select did from sys_bus_info where bid = #{bid}")
    Long getBusInfoDid(@Param("bid") Long bid);


    /**
     * 查询did负责的所有bid
     * @param did
     * @return
     */
    @Select("select bid from sys_bus_info where did = #{did}")
    List<Long> showBid(Long did);

    /**
     * 修改公车表的负责人
     * @param did
     * @param bid
     * @return
     */
    @Update("update sys_bus_info set did = #{did} where bid = #{bid}")
    boolean updateDid(@Param("did") Long did ,@Param("bid") Long bid);


    /**
     * 展示历史负责人信息
     * @param page
     * @return
     */
    @Select("select did, dname, dphone, status from sys_director where status = 1")
    List<Director> showHistoryDirector(Page<Director> page);




}
